package lt.marsrutai.mobile.android.activity.intent;

import java.util.ArrayList;
import java.util.List;

import lt.marsrutai.mobile.android.activity.FastestRoutesSearchActivity;
import lt.marsrutai.mobile.android.widget.DialogChoiceItem;
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.os.Parcelable;

public class FastestRoutesSearchIntentHolder extends IntentHolder {

    private static final String SELECTED_LOCATION = "selectedLocation";
    private static final String STOP_NAMES = "stopNames";
    private static final String SELECTED_DATE = "selectedDate";
    private static final String SCOPE_FOLDER = "scopeFolder";
    private static final String DIALOG_OWNER_ID = "dialogOwnerId";
    private static final String DIALOG_TITLE = "title";
    private static final String DIALOG_CHOICES = "dialogChoices";

    public FastestRoutesSearchIntentHolder(Activity sourceActivity) {
        super(sourceActivity, FastestRoutesSearchActivity.class);
    }

    public FastestRoutesSearchIntentHolder(Intent intent) {
        super(intent);
    }

    public FastestRoutesSearchIntentHolder(Bundle bundle) {
        super(bundle);
    }

    public void setScopeFolder(String scopeFolder) {
        intent.putExtra(SCOPE_FOLDER, scopeFolder);
    }

    public String getScopeFolder() {
        return intent.getStringExtra(SCOPE_FOLDER);
    }

    public void setDialogTitle(String title) {
        intent.putExtra(DIALOG_TITLE, title);
    }

    public String getDialogTitle() {
        return intent.getStringExtra(DIALOG_TITLE);
    }

    public void setDialogOwnerId(int ownerId) {
        intent.putExtra(DIALOG_OWNER_ID, ownerId);
    }

    public int getDialogOwnerId() {
        return intent.getIntExtra(DIALOG_OWNER_ID, 0);
    }

    public void setDialogChoices(DialogChoiceItem[] dialogChoices) {
        intent.putExtra(DIALOG_CHOICES, dialogChoices);
    }

    public DialogChoiceItem[] getDialogChoices() {
        Parcelable[] parcelables = intent.getParcelableArrayExtra(DIALOG_CHOICES);
        
        if (parcelables == null) {
            return null;
        }
        
        DialogChoiceItem[] dialogChoices = new DialogChoiceItem[parcelables.length];
        for (int i = 0; i < dialogChoices.length; i++) {
            dialogChoices[i] = (DialogChoiceItem) parcelables[i];
        }
        return dialogChoices;
    }

    public void setCurrentlySelectedDate(long time) {
        intent.putExtra(SELECTED_DATE, time);
    }

    public long getCurrentlySelectedDate() {
        return intent.getLongExtra(SELECTED_DATE, 0);
    }

    public void setStopNames(List<String> stopNames) {
        intent.putStringArrayListExtra(STOP_NAMES, new ArrayList<String>(stopNames));
    }

    public List<String> getStopNames() {
        return intent.getStringArrayListExtra(STOP_NAMES);
    }

    public void setSelectedLocation(Location location) {
        intent.putExtra(SELECTED_LOCATION, location);
    }

    public Location getSelectedLocation() {
        return intent.getParcelableExtra(SELECTED_LOCATION);
    }

}